package io.renren.modules.generator.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.app.annotation.Login;
import io.renren.modules.app.annotation.LoginUser;
import io.renren.modules.app.entity.UserEntity;
import io.renren.modules.generator.entity.TbUserMovieCollectionEntity;
import io.renren.modules.generator.service.TbUserMovieCollectionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.java.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;

/**
 * @Description:
 * @Author: Tianyu Xiao
 * @CreateDate: 2021/10/13  20:18
 */
@RestController
@RequestMapping("app/user/movie/collection")
@Api("客户端-用户电影偏好管理")
public class UserMovieCollectionController {
    @Autowired
    private TbUserMovieCollectionService tbUserMovieCollectionService;

    /**
     * 想看列表
     */
    @GetMapping("/wanna/list")
    @ApiOperation("想看的电影列表")
    @Login
    public R listWanna(@RequestParam Map<String, Object> params,@LoginUser UserEntity user){
        params.put("type",2);
        params.put("userId",user.getUserId());
        PageUtils page = tbUserMovieCollectionService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @PostMapping("/wanna/save")
    @ApiOperation("保存一个想看的电影")
    @Login
    public R saveWanna(@RequestBody TbUserMovieCollectionEntity tbUserMovieCollection,@LoginUser UserEntity user){
        tbUserMovieCollection.setType(2);
        tbUserMovieCollection.setUserId(user.getUserId());
        tbUserMovieCollectionService.save(tbUserMovieCollection);
        return R.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/wanna/delete")
    @ApiOperation("批量删除想看的电影")
    @Login
    public R deleteWanna(@RequestBody Integer[] ids,@LoginUser UserEntity user){
        tbUserMovieCollectionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }


    /*------------------------------------------------------------------------*/


    /**
     * 已看列表
     */
    @GetMapping("/looked/list")
    @ApiOperation("已看的电影列表")
    @Login
    public R list(@RequestParam Map<String, Object> params,@LoginUser UserEntity user){
        params.put("type",1);
        params.put("userId",user.getUserId());
        PageUtils page = tbUserMovieCollectionService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @PostMapping("/looked/save")
    @ApiOperation("保存一个已看的电影")
    @Login
    public R save(@RequestBody TbUserMovieCollectionEntity tbUserMovieCollection,@LoginUser UserEntity user){
        tbUserMovieCollection.setType(1);
        tbUserMovieCollection.setUserId(user.getUserId());
        tbUserMovieCollectionService.save(tbUserMovieCollection);
        return R.ok();
    }

    /**
     * 已看删除
     */
    @DeleteMapping("/looked/delete")
    @ApiOperation("批量删除已看的电影")
    @Login
    public R delete(@RequestBody Integer[] ids,@LoginUser UserEntity user){
        tbUserMovieCollectionService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }




}
